package sd.czw.com.miemiegoushop.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import butterknife.Bind;
import sd.czw.com.miemiegoushop.R;
import sd.czw.com.miemiegoushop.base.CzwBaseActivity;

/**
 * Created by czw
 * desc 描述：
 * on 2017/9/28.
 */
public class CoolSpaningActivity2 extends CzwBaseActivity {

    @Bind(R.id.image)
    ImageView image;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.collbar)
    CollapsingToolbarLayout collbar;
    @Bind(R.id.appbar)
    AppBarLayout appbar;

    @Override
    public int getLayoutId() {
        return R.layout.activity_collspning_two;
    }

    @Override
    public void initView() {

        setCollbarTitle();

        setToolbarTitle();

    }

    private void setToolbarTitle() {
        toolbar.setTitle("哈哈哈哈");
        toolbar.setTitleTextColor(Color.WHITE);
        toolbar.setNavigationIcon(R.mipmap.back);
        toolbar.inflateMenu(R.menu.toolbar_men);
        toolbar.getMenu().findItem(R.id.item_search).setVisible(true);
        toolbar.getMenu().findItem(R.id.item_one).setVisible(false);
    }

    private void setCollbarTitle() {
        collbar.setTitle("");
        collbar.setCollapsedTitleTextColor(getResources().getColor(R.color.XFrame_white));
        collbar.setExpandedTitleColor(Color.WHITE);
    }

    @Override
    public void initData() {


        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onBackPressed();
            }
        });

        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                if (item.getItemId() == R.id.item_search){
                    Toast.makeText(CoolSpaningActivity2.this, "搜索", Toast.LENGTH_SHORT).show();
                }
                return false;
            }
        });


        appbar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                Log.e("zhouwei","appbarHeight:"+appBarLayout.getHeight()+" getTotalScrollRange:"+appBarLayout.getTotalScrollRange()+" offSet:"+verticalOffset);
                if(Math.abs(verticalOffset) >= appBarLayout.getTotalScrollRange()){
                    toolbar.setTitleTextColor(getResources().getColor(R.color.XFrame_white));
                    collbar.setTitle("哈哈哈");
                }else{
                    collbar.setTitle("");
                }
            }
        });
    }

}
